home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / filesys.h < prev    next >
C/C++ Source or Header  |  1998-10-29  |  15KB  |  481 lines

  1. /*
  2.  * NOTE: This file only works if sizeof(int) == 2!
  3.  * UNLESS: you have an ANSI compiler and use prototypes
  4.  *
  5.  * Copyright 1991,1992 Eric R. Smith. This file may be re-distributed
  6.  * as long as this notice remains intact.
  7.  */
  8.  
  9. #ifndef _filesys_h
  10. #define _filesys_h
  11.  
  12. #ifndef P_
  13. # ifdef __STDC__
  14. #  define P_(x) x
  15. # else
  16. #  define P_(x) ()
  17. # endif
  18. #endif
  19.  
  20. #ifdef _SHORTINT
  21. #define _wORD int
  22. #endif
  23.  
  24. #ifndef _wORD
  25. #ifdef __MSHORT__        /* 16 bit integers? */
  26. #define _wORD int
  27. #else
  28. #define _wORD short
  29. #endif
  30. #endif
  31.  
  32. #define NAME_MAX 32
  33. #define PATH_MAX 128
  34.  
  35. struct filesys;        /* forward declaration */
  36. struct devdrv;        /* ditto */
  37.  
  38. typedef struct f_cookie {
  39.     struct filesys *fs;    /* filesystem that knows about this cookie */
  40.     unsigned short    dev;        /* device info (e.g. Rwabs device number) */
  41.     unsigned short    aux;        /* extra data that the file system may want */
  42.     long    index;        /* this+dev uniquely identifies a file */
  43. } fcookie;
  44.  
  45. /* structure for opendir/readdir/closedir */
  46. typedef struct dirstruct {
  47.     fcookie fc;        /* cookie for this directory */
  48.     unsigned short    index;        /* index of the current entry */
  49.     unsigned short    flags;        /* flags (e.g. tos or not) */
  50. #define TOS_SEARCH    0x01
  51.     char    fsstuff[60];    /* anything else the file system wants */
  52.                 /* NOTE: this must be at least 45 bytes */
  53. } DIR;
  54.  
  55. /* structure for getxattr */
  56. typedef struct xattr {
  57.     unsigned short    mode;
  58. /* file types */
  59. #define S_IFMT    0170000        /* mask to select file type */
  60. #define S_IFCHR    0020000        /* BIOS special file */
  61. #define S_IFDIR    0040000        /* directory file */
  62. #define S_IFREG 0100000        /* regular file */
  63. #define S_IFIFO 0120000        /* FIFO */
  64. #define S_IMEM    0140000        /* memory region or process */
  65. #define S_IFLNK    0160000        /* symbolic link */
  66.  
  67. /* special bits: setuid, setgid, sticky bit */
  68. #define S_ISUID    04000
  69. #define S_ISGID 02000
  70. #define S_ISVTX    01000
  71.  
  72. /* file access modes for user, group, and other*/
  73. #define S_IRUSR    0400
  74. #define S_IWUSR 0200
  75. #define S_IXUSR 0100
  76. #define S_IRGRP 0040
  77. #define S_IWGRP    0020
  78. #define S_IXGRP    0010
  79. #define S_IROTH    0004
  80. #define S_IWOTH    0002
  81. #define S_IXOTH    0001
  82. #define DEFAULT_DIRMODE (0777)
  83. #define DEFAULT_MODE    (0666)
  84.     long    index;
  85.     unsigned short    dev;
  86.     unsigned short    reserved1;
  87.     unsigned short    nlink;
  88.     unsigned short    uid;
  89.     unsigned short    gid;
  90.     long    size;
  91.     long    blksize, nblocks;
  92.     short    mtime, mdate;
  93.     short    atime, adate;
  94.     short    ctime, cdate;
  95.     short    attr;
  96.     short    reserved2;
  97.     long    reserved3[2];
  98. } XATTR;
  99.  
  100. typedef struct fileptr {
  101.     short    links;        /* number of copies of this descriptor */
  102.     unsigned short    flags;        /* file open mode and other file flags */
  103.     long    pos;        /* position in file */
  104.     long    devinfo;    /* device driver specific info */
  105.     fcookie    fc;        /* file system cookie for this file */
  106.     struct devdrv *dev; /* device driver that knows how to deal with this */
  107.     struct fileptr *next; /* link to next fileptr for this file */
  108. } FILEPTR;
  109.  
  110. /* lock structure */
  111. struct flock {
  112.     short l_type;            /* type of lock */
  113. #define F_RDLCK        O_RDONLY
  114. #define F_WRLCK        O_WRONLY
  115. #define F_UNLCK        3
  116.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  117.     long l_start;            /* start of locked region */
  118.     long l_len;            /* length of locked region */
  119.     short l_pid;            /* pid of locking process
  120.                         (F_GETLK only) */
  121. };
  122.  
  123. /* LOCK structure used by the kernel internally */
  124.  
  125. typedef struct ilock {
  126.     struct flock l;
  127.     struct ilock *next;
  128.     long  reserved[4];
  129. } LOCK;
  130.  
  131. typedef struct devdrv {
  132.     long (*open)    P_((FILEPTR *f));
  133.     long (*write)    P_((FILEPTR *f, char *buf, long bytes));
  134.     long (*read)    P_((FILEPTR *f, char *buf, long bytes));
  135.     long (*lseek)    P_((FILEPTR *f, long where, _wORD whence));
  136.     long (*ioctl)    P_((FILEPTR *f, _wORD mode, void *buf));
  137.     long (*datime)    P_((FILEPTR *f, _wORD *timeptr, _wORD rwflag));
  138.     long (*close)    P_((FILEPTR *f, _wORD pid));
  139.     long (*select)    P_((FILEPTR *f, long proc, _wORD mode));
  140.     void (*unselect) P_((FILEPTR *f, long proc, _wORD mode));
  141.     long    reserved[3];    /* reserved for future use */
  142. } DEVDRV;
  143.  
  144. typedef struct filesys {
  145.     struct    filesys    *next;    /* link to next file system on chain */
  146.     long    fsflags;
  147. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  148. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  149. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  150. #define    FS_LONGPATH    0x08    /* file system understands "size" argument to
  151.                    "getname" */
  152.  
  153.     long    (*root) P_((_wORD drv, fcookie *fc));
  154.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  155.     long    (*creat) P_((fcookie *dir, char *name, unsigned _wORD mode,
  156.                 _wORD attrib, fcookie *fc));
  157.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  158.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  159.     long    (*chattr) P_((fcookie *fc, _wORD attr));
  160.     long    (*chown) P_((fcookie *fc, _wORD uid, _wORD gid));
  161.     long    (*chmode) P_((fcookie *fc, unsigned _wORD mode));
  162.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned _wORD mode));
  163.     long    (*rmdir) P_((fcookie *dir, char *name));
  164.     long    (*remove) P_((fcookie *dir, char *name));
  165.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname,
  166.                 _wORD size));
  167.     long    (*rename) P_((fcookie *olddir, char *oldname,
  168.                 fcookie *newdir, char *newname));
  169.     long    (*opendir) P_((DIR *dirh, _wORD tosflag));
  170.     long    (*readdir) P_((DIR *dirh, char *nm, _wORD nmlen, fcookie *fc));
  171.     long    (*rewinddir) P_((DIR *dirh));
  172.     long    (*closedir) P_((DIR *dirh));
  173.     long    (*pathconf) P_((fcookie *dir, _wORD which));
  174.     long    (*dfree) P_((fcookie *dir, long *buf));
  175.     long    (*writelabel) P_((fcookie *dir, char *name));
  176.     long    (*readlabel) P_((fcookie *dir, char *name, _wORD namelen));
  177.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  178.     long    (*readlink) P_((fcookie *dir, char *buf, _wORD len));
  179.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  180.                 fcookie *todir, char *toname));
  181.     long    (*fscntl) P_((fcookie *dir, char *name, _wORD cmd, long arg));
  182.     long    (*dskchng) P_((_wORD drv));
  183.     long    (*release) P_((fcookie *fc));
  184.     long    (*dupcookie) P_((fcookie *dest, fcookie *src));
  185.  
  186. } FILESYS;
  187.  
  188. /*
  189.  * this is the structure passed to loaded file systems to tell them
  190.  * about the kernel
  191.  */
  192.  
  193. typedef long (*_LongFunc)();
  194.  
  195. struct kerinfo {
  196.     short    maj_version;    /* kernel version number */
  197.     short    min_version;    /* minor kernel version number */
  198.     unsigned short default_mode;    /* default file access mode */
  199.     short    reserved1;    /* room for expansion */
  200.  
  201. /* OS functions */
  202.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  203.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  204.  
  205. /* media change vector */
  206.     void    (*drvchng) P_((short));
  207.  
  208. /* Debugging stuff */
  209.     void    (*trace) P_((char *, ...));
  210.     void    (*debug) P_((char *, ...));
  211.     void    (*alert) P_((char *, ...));
  212.     void    (*fatal) P_((char *, ...));
  213.  
  214. /* memory allocation functions */
  215.     void *    (*kmalloc) P_((long));
  216.     void    (*kfree) P_((void *));
  217.     void *    (*umalloc) P_((long));
  218.     void    (*ufree) P_((void *));
  219.  
  220. /* utility functions for string manipulation */
  221.     short    (*strnicmp) P_((char *, char *, _wORD));
  222.     short    (*stricmp) P_((char *, char *));
  223.     char *    (*strlwr) P_((char *));
  224.     char *    (*strupr) P_((char *));
  225.     short    (*sprintf) P_((char *, char *, ...));
  226.  
  227. /* utility functions for manipulating time */
  228.     void    (*millis_time) P_((unsigned long, _wORD *));
  229.     long    (*unixtim) P_((unsigned _wORD, unsigned _wORD));
  230.     long    (*dostim) P_((long));
  231.  
  232. /* utility functions for dealing with pauses */
  233.     void    (*nap) P_((unsigned short));
  234.     void    (*sleep) P_((_wORD que, long cond));
  235.     void    (*wake) P_((_wORD que, long cond));
  236.     void    (*wakeselect) P_((long param));
  237.  
  238. /* file system utility functions */
  239.     short    (*denyshare) P_((FILEPTR *, FILEPTR *));
  240.     LOCK *    (*denylock) P_((LOCK *, LOCK *));
  241.  
  242. /* reserved for future use */
  243.     long    res2[9];
  244. };
  245.  
  246. /* flags for open() modes */
  247. #define O_RWMODE      0x03    /* isolates file read/write mode */
  248. #    define O_RDONLY    0x00
  249. #    define O_WRONLY    0x01
  250. #    define O_RDWR    0x02
  251. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  252.  
  253. #define O_APPEND    0x08    /* all writes go to end of file */
  254.  
  255. #define O_SHMODE    0x70    /* isolates file sharing mode */
  256. #    define O_COMPAT    0x00    /* compatibility mode */
  257. #    define O_DENYRW    0x10    /* deny both read and write access */
  258. #    define O_DENYW    0x20    /* deny write access to others */
  259. #    define O_DENYR    0x30    /* deny read access to others */
  260. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  261.  
  262. #define O_NOINHERIT    0x80    /* children don't get this file descriptor */
  263.  
  264. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  265. #define O_CREAT        0x200    /* create file if it doesn't exist */
  266. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  267. #define O_EXCL        0x800    /* fail open if file exists */
  268.  
  269. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  270.  
  271. #define O_GLOBAL    0x1000    /* for Fopen: opens a global file handle */
  272.  
  273. /* kernel mode bits -- the user can't set these! */
  274. #define O_TTY        0x2000    /* FILEPTR refers to a terminal */
  275. #define O_HEAD        0x4000    /* FILEPTR is the master side of a fifo */
  276. #define O_LOCK        0x8000    /* FILEPTR has had locking Fcntl's performed */
  277.  
  278.  
  279. /* GEMDOS file attributes */
  280.  
  281. /* macros to be applied to FILEPTRS to determine their type */
  282. #define is_terminal(f) (f->flags & O_TTY)
  283.  
  284. /* lseek() origins */
  285. #define    SEEK_SET    0        /* from beginning of file */
  286. #define    SEEK_CUR    1        /* from current location */
  287. #define    SEEK_END    2        /* from end of file */
  288.  
  289. /* The requests for Dpathconf() */
  290. #define DP_IOPEN    0    /* internal limit on # of open files */
  291. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  292. #define DP_PATHMAX    2    /* max path name length */
  293. #define DP_NAMEMAX    3    /* max length of an individual file name */
  294. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  295. #define DP_TRUNC    5    /* file name truncation behavior */
  296. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  297. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  298. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  299. #define DP_CASE        6    /* file name case conversion behavior */
  300. #    define    DP_CASESENS    0    /* case sensitive */
  301. #    define    DP_CASECONV    1    /* case always converted */
  302. #    define    DP_CASEINSENS    2    /* case insensitive, preserved */
  303.  
  304. #define DP_MAXREQ    6    /* highest legal request */
  305.  
  306. /* Dpathconf and Sysconf return this when a value is not limited
  307.    (or is limited only by available memory) */
  308.  
  309. #define UNLIMITED    0x7fffffffL
  310.  
  311. /* various character constants and defines for TTY's */
  312. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  313.  
  314. /* defines for tty_read */
  315. #define RAW    0
  316. #define COOKED    0x1
  317. #define NOECHO    0
  318. #define ECHO    0x2
  319. #define ESCSEQ    0x04        /* cursor keys, etc. get escape sequences */
  320.  
  321. /* constants for various Fcntl commands */
  322. /* constants for Fcntl calls */
  323. #define F_DUPFD        0        /* handled by kernel */
  324. #define F_GETFD        1        /* handled by kernel */
  325. #define F_SETFD        2        /* handled by kernel */
  326. #    define FD_CLOEXEC    1    /* close on exec flag */
  327.  
  328. #define F_GETFL        3        /* handled by kernel */
  329. #define F_SETFL        4        /* handled by kernel */
  330. #define F_GETLK        5
  331. #define F_SETLK        6
  332. #define F_SETLKW    7
  333.  
  334. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  335. #define FIONREAD    (('F'<< 8) | 1)
  336. #define FIONWRITE    (('F'<< 8) | 2)
  337. #define TIOCGETP    (('T'<< 8) | 0)
  338. #define TIOCSETP    (('T'<< 8) | 1)
  339. #define TIOCSETN    TIOCSETP
  340. #define TIOCGETC    (('T'<< 8) | 2)
  341. #define TIOCSETC    (('T'<< 8) | 3)
  342. #define TIOCGLTC    (('T'<< 8) | 4)
  343. #define TIOCSLTC    (('T'<< 8) | 5)
  344. #define TIOCGPGRP    (('T'<< 8) | 6)
  345. #define TIOCSPGRP    (('T'<< 8) | 7)
  346. #define TIOCFLUSH    (('T'<< 8) | 8)
  347. #define TIOCSTOP    (('T'<< 8) | 9)
  348. #define TIOCSTART    (('T'<< 8) | 10)
  349. #define TIOCGWINSZ    (('T'<< 8) | 11)
  350. #define TIOCSWINSZ    (('T'<< 8) | 12)
  351. #define TIOCGXKEY    (('T'<< 8) | 13)
  352. #define TIOCSXKEY    (('T'<< 8) | 14)
  353. #define TIOCIBAUD    (('T'<< 8) | 18)
  354. #define TIOCOBAUD    (('T'<< 8) | 19)
  355. #define TIOCCBRK    (('T'<< 8) | 20)
  356. #define TIOCSBRK    (('T'<< 8) | 21)
  357. #define TIOCGFLAGS    (('T'<< 8) | 22)
  358. #define TIOCSFLAGS    (('T'<< 8) | 23)
  359.  
  360. #define TCURSOFF    (('c'<< 8) | 0)
  361. #define TCURSON        (('c'<< 8) | 1)
  362. #define TCURSBLINK    (('c'<< 8) | 2)
  363. #define TCURSSTEADY    (('c'<< 8) | 3)
  364. #define TCURSSRATE    (('c'<< 8) | 4)
  365. #define TCURSGRATE    (('c'<< 8) | 5)
  366.  
  367. #define PPROCADDR    (('P'<< 8) | 1)
  368. #define PBASEADDR    (('P'<< 8) | 2)
  369. #define PCTXTSIZE    (('P'<< 8) | 3)
  370. #define PSETFLAGS    (('P'<< 8) | 4)
  371. #define PGETFLAGS    (('P'<< 8) | 5)
  372. #define PTRACESFLAGS    (('P'<< 8) | 6)
  373. #define PTRACEGFLAGS    (('P'<< 8) | 7)
  374. #    define    P_ENABLE    (1 << 0)    /* enable tracing */
  375.  
  376. #define PTRACEGO    (('P'<< 8) | 8)
  377. #define PTRACEFLOW    (('P'<< 8) | 9)
  378. #define PTRACESTEP    (('P'<< 8) | 10)
  379. #define PTRACE11    (('P'<< 8) | 11)    /* unused, reserved */
  380.  
  381. #define SHMGETBLK    (('M'<< 8) | 0)
  382. #define SHMSETBLK    (('M'<< 8) | 1)
  383.  
  384. /* terminal control constants (tty.sg_flags) */
  385. #define T_CRMOD        0x0001
  386. #define T_CBREAK    0x0002
  387. #define T_ECHO        0x0004
  388. #define T_RAW        0x0010
  389. #define T_TOS        0x0080
  390. #define T_TOSTOP    0x0100
  391. #define T_XKEY        0x0200        /* Fread returns escape sequences for
  392.                        cursor keys, etc. */
  393.  
  394. /* the following are terminal status flags (tty.state) */
  395. /* (the low byte of tty.state indicates a part of an escape sequence still
  396.  * hasn't been read by Fread, and is an index into that escape sequence)
  397.  */
  398. #define TS_ESC        0x00ff
  399. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  400. #define TS_COOKED    0x8000        /* interpret control chars */
  401.  
  402. /* structures for terminals */
  403. struct tchars {
  404.     char t_intrc;
  405.     char t_quitc;
  406.     char t_startc;
  407.     char t_stopc;
  408.     char t_eofc;
  409.     char t_brkc;
  410. };
  411.  
  412. struct ltchars {
  413.     char t_suspc;
  414.     char t_dsuspc;
  415.     char t_rprntc;
  416.     char t_flushc;
  417.     char t_werasc;
  418.     char t_lnextc;
  419. };
  420.  
  421. struct sgttyb {
  422.     char sg_ispeed;
  423.     char sg_ospeed;
  424.     char sg_erase;
  425.     char sg_kill;
  426.     unsigned short sg_flags;
  427. };
  428.  
  429. struct winsize {
  430.     short    ws_row;
  431.     short    ws_col;
  432.     short    ws_xpixel;
  433.     short    ws_ypixel;
  434. };
  435.  
  436. struct xkey {
  437.     short    xk_num;
  438.     char    xk_def[8];
  439. };
  440.  
  441. struct tty {
  442.     short        pgrp;        /* process group of terminal */
  443.     short        state;        /* terminal status, e.g. stopped */
  444.     short        use_cnt;    /* number of times terminal is open */
  445.     short        res1;        /* reserved for future expansion */
  446.     struct sgttyb     sg;
  447.     struct tchars     tc;
  448.     struct ltchars     ltc;
  449.     struct winsize    wsiz;
  450.     long        rsel;        /* selecting process for read */
  451.     long        wsel;        /* selecting process for write */
  452.     char        *xkey;        /* extended keyboard table */
  453.     long        rsrvd[3];    /* reserved for future expansion */
  454. };
  455.  
  456. /* defines and declarations for Dcntl operations */
  457.  
  458. #define DEV_INSTALL    0xde02
  459. #define DEV_NEWBIOS    0xde01
  460. #define DEV_NEWTTY    0xde00
  461.  
  462. struct dev_descr {
  463.     DEVDRV    *driver;
  464.     short    dinfo;
  465.     short    flags;
  466.     struct tty *tty;
  467.     long    reserved[4];
  468. };
  469.  
  470. /* defines for TOS attribute bytes */
  471. #ifndef FA_RDONLY
  472. #define           FA_RDONLY           0x01
  473. #define           FA_HIDDEN           0x02
  474. #define           FA_SYSTEM           0x04
  475. #define           FA_LABEL               0x08
  476. #define           FA_DIR               0x10
  477. #define           FA_CHANGED           0x20
  478. #endif
  479.  
  480. #endif /* _filesys_h */
  481.